<?php
/* Set Reporting Errors */
set_error_reporting($s_Log_Path);

/* Start an output buffer */
ob_start();

// <editor-fold defaultstate="collapsed" desc="Config Session">
session_name(md5($s_WebTitle));
session_cache_limiter('');
//ini_set('session.cookie_domain', '.denybuddy.com');
//ini_set('session.cookie_domain', 'localhost');
session_start();
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="Remove Striptag - Global Variables">
unregister_globals();

if (get_magic_quotes_gpc()) {
    remove_strip_slashes($_REQUEST);
    remove_strip_slashes($_GET);
    remove_strip_slashes($_POST);
    remove_strip_slashes($_COOKIE);
}
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="Define Variable">
$s_category1          = '';
$s_category2          = '';
$s_category3          = '';
$s_category4          = '';
$s_category5          = '';
$s_category6          = '';
$s_category7          = '';
$s_category8          = '';
$s_category9          = '';
$s_category10         = '';
$s_category11         = '';
$s_category12         = '';
$s_category13         = '';
$s_category14         = '';
$s_category15         = '';
$s_category16         = '';
$s_category17         = '';
$s_category18         = '';
$s_category19         = '';
$s_category20         = '';
$s_category_course    = '';
$s_category_team      = '';
$s_category_level     = '';
$s_category_crew      = '';

$s_field1   = '';
$s_field2   = '';
$s_field3   = '';
$s_keyword1 = '';
$s_keyword2 = '';
$s_keyword3 = '';

$a_filterings = array(
    'category1'          => '',
    'category2'          => '',
    'category3'          => '',
    'category4'          => '',
    'category5'          => '',
    'category6'          => '',
    'category7'          => '',
    'category8'          => '',
    'category9'          => '',
    'category10'         => '',
    'category11'         => '',
    'category12'         => '',
    'category13'         => '',
    'category14'         => '',
    'category15'         => '',
    'category16'         => '',
    'category17'         => '',
    'category18'         => '',
    'category19'         => '',
    'category20'         => '',
    'category_course'    => '',
    'category_team'      => '',
    'category_level'     => '',
    'category_crew'      => '',
    'field1'             => '',
    'field2'             => '',
    'field3'             => '',
    'keyword1'           => '',
    'keyword2'           => '',
    'keyword3'           => '',
);

$a_css_files = $a_js_files = $a_js_class = $a_DiLe = $a_DiHoc = array ( );

$s_SeverName  = '';
$s_ScriptName = '';

$s_PPO_ModuleID = '';
$s_PPO_ActionID = '';

$s_Action = '';
$i_Page   = '';

$s_QueryString      = '';
$s_QueryString_Page = '';
$s_InputString      = '';

$s_Pagination  = '';
$b_Menu_Closed = false;
$s_Page_Start  = 0;

// <editor-fold defaultstate="collapsed" desc="Get Data From Cache">
$a_PPO_Pages       = access_cachefile($s_Cache_Path, 'passport_pages'   , array('db_conn' => $db_conn));
$a_Nganh           = access_cachefile($s_Cache_Path, 'team'             , array('db_conn' => $db_conn));
$a_Cap             = access_cachefile($s_Cache_Path, 'level'            , array('db_conn' => $db_conn));
$a_Doi             = access_cachefile($s_Cache_Path, 'crew'             , array('db_conn' => $db_conn));
$a_PhanBan         = access_cachefile($s_Cache_Path, 'usercrew'         , array('db_conn' => $db_conn));
$a_Loai_TaiKhoan   = access_cachefile($s_Cache_Path, 'usertype'         , array('db_conn' => $db_conn));
$a_XepHang         = access_cachefile($s_Cache_Path, 'userrank'         , array('db_conn' => $db_conn));
$a_MoiQuanHe       = access_cachefile($s_Cache_Path, 'relationship'     , array('db_conn' => $db_conn));
$a_Dot_KiemTra     = access_cachefile($s_Cache_Path, 'examtype'         , array('db_conn' => $db_conn));
$a_SoLan_KiemTra   = access_cachefile($s_Cache_Path, 'examtime'         , array('db_conn' => $db_conn));
$a_ChuyenCan_Info  = access_cachefile($s_Cache_Path, 'attendance_card'  , array('db_conn' => $db_conn, 'loai_chuyencan' => array_keys($a_Loai_ChuyenCan)));

foreach ($a_ChuyenCan_Info as $sKey => $aValue) {
    switch ($sKey) {
        case 'LE':
            foreach ($aValue as $key => $value) {
                $a_DiLe[$key] = $value['option_name'];
            }
            break;

        case 'HOC':
            foreach ($aValue as $key => $value) {
                $a_DiHoc[$key] = $value['option_name'];
            }
            break;

        default:
            break;
    }
}
// </editor-fold>

if (is_array($_REQUEST) == true) {
    if($db_conn) {
        $_REQUEST = db_real_escape_string($db_conn, $_REQUEST);
    }
    foreach($a_filterings as $v_key => $v_value) {
        if(isset($_REQUEST[$v_key])) {
            $v_value = $_REQUEST[$v_key];
            if(is_array($v_value)) {
                $v_value = array_values($v_value);
                foreach($v_value as $v_idx => $v_val) {
                    $s_QueryString  = $s_QueryString . '&amp;' . $v_key . '[' . $v_idx . ']=' . $v_val;
                    $v_input_field  = '<input type="hidden" name="' . $v_key . '[' . $v_idx . ']" value="' . $v_val . '"/>' . "\n";
                    $s_InputString  = $s_InputString . $v_input_field;
                }
            }
            else {
                $s_QueryString      = $s_QueryString . '&amp;' . $v_key . '=' . $v_value;
                $v_input_field      = '<input type="hidden" name="' . $v_key . '" value="' . $v_value . '"/>' . "\n";
                $s_InputString      = $s_InputString . $v_input_field;
            }
            $v_variable     = 's_' . $v_key;
            $$v_variable    = $v_value;

            $a_filterings[$v_key] = $v_value;
        }
        else {
            $s_QueryString  = $s_QueryString . '&amp;' . $v_key . '=' . $v_value;
            $v_input_field  = '<input type="hidden" name="' . $v_key . '" value="' . $v_value . '"/>' . "\n";
            $s_InputString  = $s_InputString . $v_input_field;
        }
    }
}

// <editor-fold defaultstate="collapsed" desc="Reset Scoretime base on Request from Client">
if ($s_category_course && $s_category_course != $a_KhoaHoc_Info['start_year']) {
    $a_tmp_scoretime = array();
    
    foreach ($a_SoLan_KiemTra as $key => $value) {
        $key = date($s_category_course . '-m-d', strtotime($key));
        
        $a_tmp_scoretime[$key] = $value;
    }
    $a_SoLan_KiemTra = $a_tmp_scoretime;
    unset($a_tmp_scoretime);
}
// </editor-fold>

if (isset($_SERVER['SERVER_NAME' ] )) { $s_SeverName    = $_SERVER['SERVER_NAME' ] ; }
if (isset($_SERVER['SCRIPT_NAME' ] )) { $s_ScriptName   = $_SERVER['SCRIPT_NAME' ] ; }
if (isset($_SERVER['QUERY_STRING'] )) { $s_QueryString  = $_SERVER['QUERY_STRING'] ; }

if(isset($_REQUEST['ppomoduleid'   ])) { $s_PPO_ModuleID  = $_REQUEST['ppomoduleid'      ] ; }
if(isset($_REQUEST['action'        ])) { $s_Action        = $_REQUEST['action'           ] ; }
if(isset($_REQUEST['page'          ])) { $i_Page          = $_REQUEST['page'             ] ; }

$s_get_valid_user_condition     = " userstatus <> 'DELETED' ";
$s_get_HUYNH_TRUONG_condition   = " (usertype = 'HUYNH_TRUONG' and $s_get_valid_user_condition) ";
$s_get_THIEU_NHI_condition      = " (usertype = 'THIEU_NHI'    and $s_get_valid_user_condition) ";

$s_ScriptName  = substr($s_ScriptName, strrpos($s_ScriptName, '/') + 1);

/**
 @var string Module ID for Passport
 @var string Action ID for Passport
 *
 */    
if($s_PPO_ModuleID == '') { $s_PPO_ModuleID = strtoupper(str_replace('.php', '', $s_ScriptName)); }
$s_PPO_ModuleID = isset($a_PPO_Pages[$s_PPO_ModuleID]) ? $a_PPO_Pages[$s_PPO_ModuleID] : $s_PPO_ModuleID;
$s_PPO_ActionID = strtoupper($s_Action);

$s_QueryString      = $s_QueryString ? substr($s_QueryString, 5) : '';
$s_QueryString_Page = $s_QueryString . ($s_QueryString ? '&amp;' : '') . 'page=' . $i_Page;
$s_InputString      = $s_InputString . '<input type="hidden" name="page"        value="' . $i_Page      . '"/>' . "\n";
// </editor-fold>
?>